package com.sikaryofficial.backend.controller;

import cn.hutool.core.text.CharSequenceUtil;
import com.sikaryofficial.backend.constant.FeedbackTypeEnum;
import com.sikaryofficial.backend.domain.dto.SysDictDataDTO;
import com.sikaryofficial.backend.domain.dto.req.FeedbackReq;
import com.sikaryofficial.backend.manager.UserFeedbackManager;
import com.sikaryofficial.common.core.exception.ServiceException;
import com.sikaryofficial.common.core.utils.HiResultUtil;
import com.sikaryofficial.common.core.web.controller.BaseController;
import com.sikaryofficial.common.core.web.domain.HiResult;
import com.sikaryofficial.common.log.annotation.Log;
import com.sikaryofficial.common.log.enums.BusinessType;
import com.sikaryofficial.system.api.model.SysMemberReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户反馈Controller
 *
 * @author qinjinyuan
 * @date 2023-11-16
 */
@RestController
@RequestMapping("/user/feedback")
@Api(tags = "用户反馈服务")
public class UserFeedbackController extends BaseController {
    @Autowired
    private UserFeedbackManager feedbackManager;

    /**
     * 注销用户
     */
    @Log(title = "注销用户", businessType = BusinessType.UPDATE)
    @PostMapping("/unsubscribe")
    @ApiOperation("注销用户")
    public HiResult<Boolean> unsubscribe(@RequestBody SysMemberReq req) {
        if (CharSequenceUtil.isBlank(req.getUserIds())) {
            throw new ServiceException("用户ID不能为空");
        }
        return HiResultUtil.success(feedbackManager.unsubscribe(req));
    }

    /**
     * 新增用户反馈
     */
    @Log(title = "用户反馈", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增用户反馈")
    public HiResult<Boolean> add(@RequestBody FeedbackReq req) {
        return HiResultUtil.success(feedbackManager.saveFeedback(req));
    }

    /**
     * 反馈类型枚举
     */
    @PostMapping("/feedbackType")
    @ApiOperation("反馈类型枚举")
    public HiResult<List<SysDictDataDTO>> getReportType() {
        FeedbackTypeEnum[] feedbackTypeEnums = FeedbackTypeEnum.values();
        List<SysDictDataDTO> result = new ArrayList<>();
        for (FeedbackTypeEnum feedbackTypeEnum : feedbackTypeEnums) {
            SysDictDataDTO sysDictDataDTO = new SysDictDataDTO();
            result.add(sysDictDataDTO);
            sysDictDataDTO.setDictLabel(feedbackTypeEnum.getName());
            sysDictDataDTO.setDictDesc(feedbackTypeEnum.getDesc());
            sysDictDataDTO.setDictValue(feedbackTypeEnum.getCode() + "");
            sysDictDataDTO.setDictType("feedback_type");
        }
        return HiResultUtil.success(result);
    }

}
